﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcAtletIS.Models
{
    [MetadataType(typeof(DisciplineListMetaData))]
    public partial class DisciplineList
    {
        public TimeSpan StartTimeSpan
        {
            get
            {
                if (!String.IsNullOrEmpty(this.StartTime) && this.StartTime.Length == 5)
                {
                    int hours = Convert.ToInt32(this.StartTime.Substring(0, 2));
                    int minutes = Convert.ToInt32(this.StartTime.Substring(3, 2));
                    return new TimeSpan(hours, minutes, 0);
                }
                if (!String.IsNullOrEmpty(this.StartTime) && this.StartTime.Length == 8)
                {
                    int hours = Convert.ToInt32(this.StartTime.Substring(0, 2));
                    int minutes = Convert.ToInt32(this.StartTime.Substring(3, 2));
                    int seconds = Convert.ToInt32(this.StartTime.Substring(6, 2));
                    return new TimeSpan(hours, minutes, seconds);
                }
                return new TimeSpan();
            }
        }
    }

    public class DisciplineListMetaData
    {
        [DisplayName("Názov")]
        public string Name { get; set; }

        [DisplayName("Popis")]
        public string Description { get; set; }
        
        [DisplayName("Čas štartu")]
        [Required(ErrorMessage = "Čas štartu je povinný údaj.")]
        [StringLength(5, ErrorMessage = "Max. dĺžka je 5 znakov.")]
        public string OfficialStartTime { get; set; }

        [DisplayName("Číslo disciplíny")]
        [Required(ErrorMessage = "Číslo disciplíny je povinný údaj.")]
        public int ExternalId { get; set; }

        [DisplayName("Deň")]
        [Required(ErrorMessage = "Deň je povinný údaj.")]
        public int Day { get; set; }

        [DisplayName("Štafeta")]
        public bool Relay { get; set; }
    }
}